package com.example.springbott.controller;

import com.example.springbott.aspactJ.OperationName;
import com.example.springbott.bean.BaseRespVo;
import com.example.springbott.bean.MarketTopic;
import com.example.springbott.common.CommonData;
import com.example.springbott.service.MarketTopicService;
import com.example.springbott.vo.ReadTopicVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author 付常莹
 * @description: TODO
 * @date 2022/11/20 21:03
 * 该Controller用于专题管理模块
 */
@RestController
@RequestMapping("admin/topic")
public class TopicController {
    @Resource
    MarketTopicService marketTopicService;
    /**
     * 该方法用于专题查询
     * @return
     * get
     */
    @RequiresPermissions("admin:topic:list")
    @GetMapping("list")
    @OperationName("1")
    public BaseRespVo list(Integer page,Integer limit,String title,String subtitle,String sort,String order){
        CommonData<MarketTopic> data = marketTopicService.list(page,limit,title,subtitle,sort,order);
        return BaseRespVo.ok(data);
    }

    /**
     * 该方法用于新增专题
     * post
     */
    @RequiresPermissions("admin:topic:create")
    @PostMapping("create")
    @OperationName("1")
    public BaseRespVo create(@RequestBody MarketTopic marketTopic){
        MarketTopic marketTopic1 = marketTopicService.createTopic(marketTopic);
        return BaseRespVo.ok(marketTopic1);
    }


    /**
     * 该方法用于专题修改前信息的回显
     * 该方法需要修改
     */
    @RequiresPermissions("admin:topic:read")
    @GetMapping("read")
    @OperationName("1")
    public BaseRespVo read(Integer id){
     ReadTopicVo data = marketTopicService.read(id);
     return BaseRespVo.ok(data);
    }


    /**
     * 该方法用于专题修改
     * post
     */
    @RequiresPermissions("admin:topic:update")
    @PostMapping("update")
    @OperationName("1")
    public BaseRespVo update(@RequestBody MarketTopic marketTopic){
        MarketTopic data = marketTopicService.update(marketTopic);
        return BaseRespVo.ok(data);
    }


    /**
     * 该方法用于删除专题
     */
    @RequiresPermissions("admin:topic:delete")
    @PostMapping("delete")
    @OperationName("1")
    public BaseRespVo delete(@RequestBody MarketTopic marketTopic){
        marketTopicService.delete(marketTopic);
        return BaseRespVo.ok(null);
    }

    /**
     * 批量删除专题
     * @param map
     * @return
     */
    @RequiresPermissions("admin:topic:batch-delete")
    @PostMapping("batch-delete")
    @OperationName("1")
    public BaseRespVo batchDelete(@RequestBody Map<String ,Integer[]> map){
        marketTopicService.batchDelete(map);
        return BaseRespVo.ok(null);
    }
}
